import java.awt.event.*;
import javax.swing.*;
import java.io.*;

final class CompileItem extends AbstractAction{
  private final Doer frame;
  CompileItem(String name,Doer frame){
    super(name);
    this.frame=frame;
    putValue(SHORT_DESCRIPTION,name);
    String iconFileName="images"+File.separator+name+".gif";
    if(new File(iconFileName).exists())putValue(SMALL_ICON,new ImageIcon(iconFileName));
  }
  public void actionPerformed(ActionEvent e){
    compileFile();
  }
  public void compileFile(){
    InterWindow interWindow=(InterWindow)frame.getTab().getComponentAt(frame.getSelect());
    try{
      File file=new File(interWindow.getDirection(),frame.getTab().getTitleAt(frame.getSelect()));
      String command="javac "+file;
      Process process=Runtime.getRuntime().exec(command);
      frame.getCMDInfo().getTextArea().setText("");
      frame.getCMDInfo().catchErr(process.getErrorStream());
    }
    catch(IOException e){
      System.err.println("IO error: " + e);
    }
  }
}
